package com.tz.farmer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tz.farmer.mapper.FarmerSummaryMapper;
import com.tz.farmer.model.FarmerSummary;
import com.tz.farmer.service.IFarmerSummaryService;
import com.tz.farmer.vo.SummaryVo;
import org.springframework.stereotype.Service;

@Service
public class FarmerSummaryServiceImpl extends ServiceImpl<FarmerSummaryMapper, FarmerSummary> implements IFarmerSummaryService {

    @Override
    public SummaryVo getFarmerSummary(String market, String channel) {
        SummaryVo response = new SummaryVo();
        // 创建查询条件
        LambdaQueryWrapper<FarmerSummary> wrapper = new LambdaQueryWrapper<FarmerSummary>()
            .eq(FarmerSummary::getMarket, market)
            .eq(FarmerSummary::getChannel, channel)
            .eq(FarmerSummary::getDeleted, 0);

        for (FarmerSummary summary : list(wrapper)) {
            switch (summary.getType()) {
                case "完成":
                    response.setFinished(summary.getCount());
                    response.setFinishedRate(summary.getRate());
                    break;
                case "合格":
                    response.setQualified(summary.getCount());
                    response.setQualifiedRate(summary.getRate());
                    break;
                case "处置":
                    response.setHandled(summary.getCount());
                    response.setHandledRate(summary.getRate());
                    break;
            }
        }

        return response;
    }
}
